﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BUS;
using DTO;

namespace CungMuaC5.Account_Admin.QuanLyTaiKhoan
{
    public partial class QuanLyTaiKhoan : System.Web.UI.Page
    {
        int MaTK = 0;
        protected void Page_Load(object sender, EventArgs e)
        {
            
            try
            {
                MaTK = int.Parse(Request.QueryString["ma"].ToString());
            }
            catch (Exception ex)
            {

            }

            FillAdmin();
            FillUser();
            FillBus();
            if (MaTK != 0)
            {

                Update();
                FillAdmin();
                FillUser();
                FillBus();
            }
        }

        private void FillBus()
        {
            BUS_TaiKhoan bus = new BUS_TaiKhoan();
            GridView4.DataSource = bus.select(2);
            GridView4.DataBind();
        }

        private void FillUser()
        {
            BUS_TaiKhoan bus = new BUS_TaiKhoan();
            GridView3.DataSource = bus.select(0);
            GridView3.DataBind();
        }
        private void Update()
        {
            BUS_TaiKhoan bus = new BUS_TaiKhoan();

            ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script language='javascript'>alert('Thực sự muốn xóa người dùng này ?');</script>");
            bool i = bus.Delete(MaTK);
            
        }
        private void FillAdmin()
        {
            BUS_TaiKhoan bus = new BUS_TaiKhoan();
            GridView2.DataSource = bus.select(1);
            GridView2.DataBind();
           
            
        }

        protected void GridView2_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            GridView2.PageIndex = e.NewPageIndex;
            FillAdmin(); 
        }

        protected void GridView3_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            GridView3.PageIndex = e.NewPageIndex;
            FillUser();
        }

        

        protected void Button1_Click(object sender, EventArgs e)
        {
            string text = TextBox3.Text;
            loc2(text, 1);
            loc3(text, 0);
            loc4(text, 2);
            
        }
        public void loc2(string text,int i)
        {
            BUS_TaiKhoan bus = new BUS_TaiKhoan();
            GridView2.DataSource = bus.Loc(text, i);
            GridView2.DataBind();
        }
        public void loc3(string text, int i)
        {
            BUS_TaiKhoan bus = new BUS_TaiKhoan();
            GridView3.DataSource = bus.Loc(text, i);
            GridView3.DataBind();
        }
        public void loc4(string text, int i)
        {
            BUS_TaiKhoan bus = new BUS_TaiKhoan();
            GridView4.DataSource = bus.Loc(text, i);
            GridView4.DataBind();
        }

        protected void GridView4_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            GridView4.PageIndex = e.NewPageIndex;
            FillBus();
        }

        protected void GridView2_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

    }
}